//--------------------------------------------------------------------------------------
// Constant Buffer Variables
//--------------------------------------------------------------------------------------

cbuffer neverChanges
{
    matrix view;
};

cbuffer changeOnResize
{
    matrix projection;
};

cbuffer changesEveryFrame
{
    matrix world;
    float4 meshColor;
    float4 lightPos;
    float4 lightColor;
};

struct VS_INPUT
{
    float4 pos : POSITION;
   // float3 norm : NORMAL;
};

struct PS_INPUT
{
    float4 pos : SV_POSITION;
    //float3 norm : TEXCOORD0;
    float3 interPos : TEXCOORD1;
};


//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
PS_INPUT VS(VS_INPUT input)
{
    PS_INPUT output = (PS_INPUT) 0;
    output.pos = mul(input.pos, world);
    output.pos = mul(output.pos, view);
    output.pos = mul(output.pos, projection);
    //output.interPos = mul(input.pos.xyz, world);
    output.interPos = input.pos.xyz;
    //output.norm = mul(input.norm, world);
    
    return output;
}


//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS(PS_INPUT input) : SV_Target
{
	float3 pixelToLight = (float3)lightPos - input.interPos;
	//float3 newNormal = normalize(input.norm);
	//float3 newDirection = normalize(pixelToLight);
	//float4 lightIntensity = lightColor/pow(length(pixelToLight),2.0);
	//float4 finalColor = saturate(lightIntensity*dot(newNormal, newDirection));
    float4 finalColor = meshColor/pow(length(pixelToLight),1.0);
    finalColor.a = 1.0;
    return finalColor;
}


//--------------------------------------------------------------------------------------
technique10 render
{
    pass P0
    {
        SetVertexShader(CompileShader(vs_4_0, VS()));
        SetGeometryShader(NULL);
        SetPixelShader(CompileShader(ps_4_0, PS()));
    }
}


